<template>
  <div class="main">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
      <el-form-item label="应用平台:" prop="name"></el-form-item>
      <el-form-item label="奖金条件" prop="region">
        <span>推荐每购买1次钻石，奖池新增</span>
        <el-input class="smallInput" v-model="ruleForm.name"></el-input>
        <span>元</span>
      </el-form-item>
      <el-form-item label="活动标题:" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="当月公司补贴奖金:" prop="name">
        <el-input class="smallInput" v-model="ruleForm.name"></el-input>
        <span>元，本月新增瓜分奖金1000.00元，本月预计可瓜分880.00元，历史累计新增奖金2000.00元</span>
      </el-form-item>
      <el-form-item label="当月抽奖奖金池:" prop="name">
        <el-input class="smallInput" v-model="ruleForm.name"></el-input>
        <span>%，预计本月新增抽奖奖金池220.00元，当前抽奖奖池1020.00元，历史累计新增奖金2000.00元</span>
      </el-form-item>
      <el-form-item label="活动时间:" prop="name">
        <el-col :span="12">最多可设置前100名，奖励概率总和100%</el-col>
      </el-form-item>
      <el-form-item label="" required>
        <el-col :span="16">
          <el-input class="smallInput" v-model="ruleForm.name"></el-input>&nbsp;-
          <el-input class="smallInput" v-model="ruleForm.name"></el-input>
          <span>名，每人得奖励</span>
          <el-input class="smallInput" v-model="ruleForm.name"></el-input>
          <span>%</span>
          <el-button type="danger">-删除</el-button>
          <el-button type="success">+添加</el-button>
        </el-col>
      </el-form-item>
      <el-form-item label="活动规则:" prop="delivery">
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>
      <el-form-item label="" prop="delivery">
        <el-input v-model="ruleForm.name" placeholder="URL地址"></el-input>
      </el-form-item>
      <el-form-item label="专题头部背景图:" prop="delivery">
        <el-upload class="avatar-uploader" accept="image/*" :action="upladUrl" name="file" :show-file-list="false"
          :on-success="uploadSuccess" :before-upload="beforeUpload">
          <!-- <img v-if="item.iconUrl" :src="item.iconUrl" class="avatar" /> -->
          <!-- <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
        </el-upload>
      </el-form-item>
      <!-- <el-form-item label="广告图:" prop="delivery">
        <el-upload class="avatar-uploader" accept="image/*" :action="upladUrl" name="file" :show-file-list="false"
          :on-success="uploadSuccess" :before-upload="beforeUpload">
          <img v-if="item.iconUrl" :src="item.iconUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item> -->
      <el-form-item label="活动时间:" prop="type">
        <div class="active_time">
          <el-select class="time" v-model="ruleForm.region" placeholder="请选择活动区域">
            <el-option label="日" value="day"></el-option>
            <el-option label="周" value="week"></el-option>
            <el-option label="月" value="month"></el-option>
            <el-option label="年" value="year"></el-option>
          </el-select>
          <div class="date_group">
            <el-form-item prop="date1">
              <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;">
              </el-date-picker>
            </el-form-item>
            <div class="line">-</div>
            <el-form-item prop="date2">
              <el-time-picker placeholder="选择时间" v-model="ruleForm.date2" style="width: 100%;"></el-time-picker>
            </el-form-item>
          </div>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        rules: {
          name: [{
              required: true,
              message: '请输入活动名称',
              trigger: 'blur'
            },
            {
              min: 3,
              max: 5,
              message: '长度在 3 到 5 个字符',
              trigger: 'blur'
            }
          ],
          region: [{
            required: true,
            message: '请选择活动区域',
            trigger: 'change'
          }],
          date1: [{
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change'
          }],
          date2: [{
            type: 'date',
            required: true,
            message: '请选择时间',
            trigger: 'change'
          }],
          type: [{
            type: 'array',
            required: true,
            message: '请至少选择一个活动性质',
            trigger: 'change'
          }],
          resource: [{
            required: true,
            message: '请选择活动资源',
            trigger: 'change'
          }],
          desc: [{
            required: true,
            message: '请填写活动形式',
            trigger: 'blur'
          }]
        }
      };
    },
    mounted() {
      console.log(11)
    },
    methods: {
      uploadSuccess() {
        console.log(1)
      },
      beforeUpload() {
        console.log(1)
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="scss" scoped="scoped">
  .active_time {
    display: flex;
  }
  .date_group {
    display: flex;
    .line {
      padding: 0 10px;
    }
  }
  /deep/.time {
    width: 80px;
    .el-input {
      width: 100% !important;
    }
  }

  .smallInput {
    width: 43px;
  }

  .main {
    padding-top: 20px;
  }
</style>
